package com.generator.purchaseManage.brandManage.service.impl;

import com.generator.purchaseManage.brandManage.dao.IBrandMapper;
import com.generator.purchaseManage.brandManage.pojo.CBrand;
import com.generator.purchaseManage.brandManage.service.IBrandService;
import com.generator.sysManage.logManage.pojo.Log;
import com.generator.util.PageModel;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0
 * @auther wumei
 * @date 2022/10/04
 * 星期六 21:07
 */
@Service
public class BrandService implements IBrandService {

    @Autowired
    private IBrandMapper brandMapper;

    public IBrandMapper getBrandMapper() {
        return brandMapper;
    }
    public void setBrandMapper(IBrandMapper brandMapper) {
        this.brandMapper = brandMapper;
    }

    /**
     *  根据条件查询品牌信息
     * @param brand
     * @return
     */
    @Override
    public PageModel<CBrand> queryBrandByCondition(CBrand brand,PageModel<CBrand> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum()<=0?1:pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize()<=0?3:pageModel.getPageSize());
        PageHelper.startPage(pageModel.getPageNum(),pageModel.getPageSize());
        List<CBrand> brandList = brandMapper.queryBrandByCondition(brand);


        PageInfo<CBrand> pageInfo = new PageInfo<CBrand>(brandList);

        pageModel.setData(new ArrayList<CBrand>(brandList));
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageInfo.getTotal());
        return pageModel;
    }

    /**
     *  查询所有品牌信息
     * @return
     */
    @Override
    public List<CBrand> queryBrandByCondition() {
        return brandMapper.queryBrandByCondition(new CBrand());
    }

    /**
     *  根据品牌名称品牌信息
     * @param brand
     * @return
     */
    @Override
    public CBrand queryBrandByName(CBrand brand) {
        return brandMapper.queryBrandByName(brand);
    }


    /**
     * 添加品牌
     * @param brand
     * @return
     */
    @Override
    public boolean addBrand(CBrand brand) {
        return brandMapper.addBrand(brand);
    }

    /**
     * 修改品牌信息
     * @param brand
     * @return
     */
    @Override
    public boolean updateBrand(CBrand brand) {
        return brandMapper.updateBrand(brand);
    }

    /**
     * 删除品牌
     * @param brand
     * @return
     */
    @Override
    public boolean deleteBrand(CBrand brand) {
        return brandMapper.deleteBrand(brand);
    }
}
